package com.example.demo.utils;

import com.example.demo.Entity.CallType;
import lombok.Data;

@Data
public class Message {

    //调用结果类型
    private CallType callType;
    //消息
    private String msg;
    //数据
    private Object data;
    //状态码
    private Integer status;
    //异常链接
    private String url;

    /**
     * 此处省略  get set toString
     **/

    public Message() {
    }

    /**
     * 错误返回
     *
     * @param callType
     * @param msg
     */
    public Message(CallType callType, String msg, Integer status, String url) {
        this.callType = callType;
        this.msg = msg;
        this.status = status;
        this.url = url;
    }

    /**
     * 成功返回
     *
     * @param callType
     * @param msg
     * @param data
     */
    public Message(CallType callType, String msg, Object data, Integer status) {
        this.callType = callType;
        this.msg = msg;
        this.data = data;
        this.status = status;
    }

    /**
     * 返回成功消息
     *
     * @param data 返回数据
     * @return
     */
    public static Message success(Object data) {
        return new Message(CallType.success, "操作成功！", data, 0);
    }

    /**
     * 返回失败消息
     *
     * @param msg
     * @return
     */
    public static Message unsuccess(String msg, String url) {
        return new Message(CallType.error, msg, -1, url);
    }
}
